<div class="layuimini-main">

    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">键</label>
            <div class="layui-input-block">
                <input type="text" name="key" id="key" lay-verify="required" lay-reqtext="键名不能为空" placeholder="请输入键名" value="" class="layui-input">
                <tip>键名不能重复</tip>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">值</label>
            <div class="layui-input-block">
                <textarea name="value" id="value" class="layui-textarea" placeholder="请输入值"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="is_edit" id="is_edit" value="0">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    checkLogin()
    layui.use(['form', 'table','element'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            element = layui.element,
            $ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (formData) {
            postData($,"/admin/etcd/set",formData.field,function (res) {
                if (parseInt(res.code) == 0) {
                    layer.msg("保存成功",{time: 1000},function (){
                        // parent.pageRefresh($,element)
                        parent.tableReload(table,"currentTableId")
                        // 关闭弹出层
                        layer.close(parentIndex);
                    })
                }else {
                    layer.msg(res.message, {time: 2000, icon: 2, shade: 0.01});
                }
            })
            return false;
        });

    });
</script>